package com.crazyice.lee.reader;

import com.crazyice.lee.data.WishSchool;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.Random;

@Slf4j
public class WishList extends RichParallelSourceFunction<WishSchool> {
    private boolean isRun=true;

    @Override
    public void run(SourceContext<WishSchool> sourceContext) throws Exception {
        Random random=new Random();
        int number=0;
        while (isRun){
            number++;
            WishSchool wishSchool=new WishSchool();
            wishSchool.setStudentId(number);
            int k=random.nextInt(8);
            for(int i=0;i<k;i++) {
                wishSchool.setSchoolId(1+random.nextInt(100));
                wishSchool.setOrderId(1+random.nextInt(8));
                sourceContext.collect(wishSchool);
            }
            if (number>=12000)break;
        }

    }

    @Override
    public void cancel() {
        isRun=false;
    }
}
